using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System.IO;

namespace <Application>
{
    public partial class frm<OwnerU>_<TableU> : System.Web.UI.Page
    {

        private DataView dv<OwnerU>_<TableU>;
        private <Database>DataClass cls<Database>Data = new <Database>DataClass();

        protected void Page_Load(object sender, EventArgs e)
        {
		    if (!Page.IsPostBack) {
			    Session["Mode"] = "";
    	<If Loop>
        	<IsPKey>
 			    Session["<FieldU>"] = "";
    	</If Loop>
    	<If Loop>
        	<IsNotPKey>
        	<And>
        	<IsIdentity>
			    Session["<FieldU>"] = "";
        	<ExitLoop>
    	</If Loop>
    	<If Loop>
        	<IsNotIdentityCount>
        	<And>
        	<IsNotPKeyCount>
			    Session["<FieldU>"] = "";
        	<ExitLoop>
    	</If Loop>

			    Session.Remove("dv<OwnerU>_<TableU>");

    	<If Loop>
   		<IsNotText>
   		<And>
   		<IsNotNText>
                            cmbFields.Items.Add("<FieldC>");
    	</If Loop>

                	    cmbCondition.Items.Add("Contains");
                	    cmbCondition.Items.Add("Equals");
                	    cmbCondition.Items.Add("Starts with...");
                	    cmbCondition.Items.Add("More than...");
                	    cmbCondition.Items.Add("Less than...");
                	    cmbCondition.Items.Add("Equal or more than...");
                	    cmbCondition.Items.Add("Equal or less than...");

			    cmbRecords.Items.Add("5");
			    cmbRecords.Items.Add("10");
			    cmbRecords.Items.Add("25");
			    cmbRecords.Items.Add("50");
			    cmbRecords.Items.Add("100");
			    cmbRecords.Items.Add("500");

        <If Loop>
          <IsFKey>
            Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>();
        </If Loop>

			    LoadGrid<OwnerU>_<TableU>();
		    }

        }


    <If Loop>
      <IsFKey>
	    private void Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>()
	    {
		    txt<FieldU>.DataSource = <OwnerU>_<TableU>_<ROwnerU>_<RTableU>DataClass<MiscTag>.List();
		    txt<FieldU>.DataValueField = "<RFieldU>";
		    txt<FieldU>.DataTextField = "<RDisplayFieldU>";
		    txt<FieldU>.DataBind();
	    }

    </If Loop>
        private void LoadGrid<OwnerU>_<TableU>()
        {
		    try {
			if ((Session["dv<OwnerU>_<TableU>"] != null)) {
				dv<OwnerU>_<TableU> = (DataView)Session["dv<OwnerU>_<TableU>"];
				// DataView was not found in the session.
		    	} else {
				dv<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.SelectAll().DefaultView;
			    	Session["dv<OwnerU>_<TableU>"] = dv<OwnerU>_<TableU>;
		    	}
                if (dv<OwnerU>_<TableU>.Count > 0)
                {
                    dv<OwnerU>_<TableU>.Sort = htmlHiddenSortExpression.Value;
                    grd<TableU>.DataSource = dv<OwnerU>_<TableU>;
                    grd<TableU>.DataBind();
                }
                else
                {
                    grd<TableU>.DataSource = null;
                    grd<TableU>.DataBind();
                }
		    }
		    catch (Exception ex)
		    {
		    	ec.ShowMessage(ex.Message, " <Head> ");
		    }
        }

        private void Add()
        {
		    Session.Remove("Mode");
		    Session["Mode"] = "Add";

		    ClearRecord();

        <If Loop>
           <IsNotIdentity>
           <And>
           <IsCheckBox>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsNumericUpDown>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsDateTimePicker>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsTextBox>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsMaskedTextBox>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsMultilineTextBox>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsRichTextBox>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsPictureBox>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsComboBox>
		    this.txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsComboBox (Db)>
		    this.txt<FieldU>.Enabled = true;
        </If Loop>
 -----------------------------------------------------<Comment>
        <If Loop>
           <IsIdentity>
           <And>
           <IsNumericUpDown>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsMaskedTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsMultilineTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsRichTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsComboBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsComboBox (Db)>
		    txt<FieldU>.Enabled = false;
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsCheckBox>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNumericUpDown> 
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsDateTimePicker>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsTextBox>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsMaskedTextBox>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsMultilineTextBox>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsRichTextBox>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsPictureBox>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsComboBox>
		    txt<FieldU>.Focus();
              <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsComboBox (Db)>
		    txt<FieldU>.Focus();
              <ExitLoop>
        </If Loop>
            <If Loop>
               <IsIdentity>
               <And>
               <IsNumericUpDown>
		    txt<FieldU>.Text = System.Convert.ToString(cls<Database>Data.getAutoID("New", "<Table>"));
            </If Loop>

		    Session["Det_<DRField>"] = null;
		    det2.UnLoadAll();
		    PnlDetail.Visible = false;
-----------------------------------------------------<Comment>
        }

        private void GetData()
        {
		    ClearRecord();

		    <OwnerU>_<TableU>Class cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>Class();
        <If Loop>
           <IsPKey>
		    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
		    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
		    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
           <ExitLoop>
        </If Loop>
		    cls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(cls<OwnerU>_<TableU>);

		    if ((cls<OwnerU>_<TableU> != null)) {
			    try {
                <If Loop>
                   <IsCheckBox>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Checked = default(string); } else { txt<FieldU>.Checked = System.Convert.ToBoolean(cls<OwnerU>_<TableU>.<Field>); }
                   <IsNumericUpDown>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = default(string); } else { txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                   <IsDateTimePicker>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = DateTime.Now.ToString(); } else { txt<FieldU>.Text = System.Convert.ToDateTime(cls<OwnerU>_<TableU>.<Field>).ToShortDateString(); }
                   <IsTextBox>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = default(string); } else { txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                   <IsMaskedTextBox>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = default(string); } else { txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                   <IsMultilineTextBox>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = default(string); } else { txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                   <IsRichTextBox>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = default(string); } else { txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                   <IsPictureBox>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = default(string); } else { txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                   <IsComboBox>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.Text = default(string); } else { txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                   <IsComboBox (Db)>
                   <And>
                   <IsNull>
                		if (cls<OwnerU>_<TableU>.<Field> is null) { txt<FieldU>.SelectedValue = default(string); } else { txt<FieldU>.SelectedValue = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
--------------------------------------------------------------------------------------------------------<Comment>
                   <IsCheckBox>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Checked = System.Convert.ToBoolean(cls<OwnerU>_<TableU>.<Field>);
                   <IsNumericUpDown>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                   <IsDateTimePicker>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToDateTime(cls<OwnerU>_<TableU>.<Field>).ToShortDateString();
                   <IsTextBox>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                   <IsMaskedTextBox>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                   <IsMultilineTextBox>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                   <IsRichTextBox>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                   <IsPictureBox>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                   <IsComboBox>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.Text = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                   <IsComboBox (Db)>
                   <And>
                   <IsNotNull>
                		txt<FieldU>.SelectedValue = System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                </If Loop>			   
		   	 }
		    	catch (Exception ex)
		    	{
		    		ec.ShowMessage(ex.Message, " <Head> ");
		    	}
		    }

		    if ((cls<OwnerU>_<TableU> != null)) {
			    try {
        <If Loop>
           <IsPKey>
                		Session["Det_<DRField>"] = cls<OwnerU>_<TableU>.<FieldU>;
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
                		Session["Det_<DRField>"] = cls<OwnerU>_<TableU>.<FieldU>;
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
                		Session["Det_<DRField>"] = cls<OwnerU>_<TableU>.<FieldU>;
           <ExitLoop>
        </If Loop>
                		Session.Remove("dv<DOwnerU>_<DTableU>");
                		det2.UnLoadAll();
                		PnlDetail.Visible = false;
                		det2.LoadGrid<DOwnerU>_<DTableU>();
		   	 } catch { }   	
		    }

        }

        private void Edit()
        {
		    Session.Remove("Mode");
		    Session["Mode"] = "Edit";

                    GetData();

        <If Loop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsNumericUpDown>
		    txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsTextBox>
		    txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsMaskedTextBox>
		    txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsMultilineTextBox>
		    txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsRichTextBox>
		    txt<FieldU>.Enabled = true;
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsComboBox (Db)>
		    txt<FieldU>.Enabled = true;
        </If Loop>
        <If Loop>
           <IsIdentity>
           <And>
           <IsNumericUpDown>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsMaskedTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsMultilineTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsRichTextBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsComboBox>
		    txt<FieldU>.Enabled = false;
           <IsIdentity>
           <And>
           <IsComboBox (Db)>
		    txt<FieldU>.Enabled = false;
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsNumericUpDown>
		    txt<FieldU>.Enabled = false;
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsTextBox>
		    txt<FieldU>.Enabled = false;
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMaskedTextBox>
		    txt<FieldU>.Enabled = false;
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsMultilineTextBox>
		    txt<FieldU>.Enabled = false;
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsRichTextBox>
		    txt<FieldU>.Enabled = false;
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsComboBox>
		    txt<FieldU>.Enabled = false;
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
           <IsComboBox (Db)>
		    txt<FieldU>.Enabled = false;
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsNumericUpDown>
		    txt<FieldU>.Enabled = false;
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsTextBox>
		    txt<FieldU>.Enabled = false;
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMaskedTextBox>
		    txt<FieldU>.Enabled = false;
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsMultilineTextBox>
		    txt<FieldU>.Enabled = false;
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsRichTextBox>
		    txt<FieldU>.Enabled = false;
           <ExitLoop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
           <IsComboBox (Db)>
		    txt<FieldU>.Enabled = false;
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsCheckBox>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsNumericUpDown>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsDateTimePicker>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsTextBox>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsMaskedTextBox>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsMultilineTextBox>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsRichTextBox>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsComboBox>
		    txt<FieldU>.Focus();
           <ExitLoop>
           <IsNotIdentity>
           <And>
           <IsNotPKey>
           <And>
           <IsComboBox (Db)>
		    txt<FieldU>.Focus();
           <ExitLoop>
        </If Loop>

		    PnlDetail.Visible = true;
        }

        private void Delete()
        {
		    Session.Remove("Mode");
		    Session["Mode"] = "Delete";

                    GetData();
                    PnlDetail.Visible = false;

        <If Loop>
           <IsCheckBox>
		    txt<FieldU>.Enabled = false;
           <IsNumericUpDown>
		    txt<FieldU>.Enabled = false;
           <IsDateTimePicker>
		    txt<FieldU>.Enabled = false;
           <IsTextBox>
		    txt<FieldU>.Enabled = false;
           <IsMaskedTextBox>
		    txt<FieldU>.Enabled = false;
           <IsMultilineTextBox>
		    txt<FieldU>.Enabled = false;
           <IsRichTextBox>
		    txt<FieldU>.Enabled = false;
           <IsPictureBox>
		    txt<FieldU>.Enabled = false;
           <IsComboBox>
		    txt<FieldU>.Enabled = false;
           <IsComboBox (Db)>
		    txt<FieldU>.Enabled = false;
        </If Loop>
        }

        private void ClearRecord()
        {
        <If Loop>
           <IsCheckBox>
        	txt<FieldU>.Text = null;
           <IsNumericUpDown>
	        txt<FieldU>.Text = System.Convert.ToString(0);
           <IsDateTimePicker>
        	txt<FieldU>.Text = null;
           <IsTextBox>
	        txt<FieldU>.Text = null;
           <IsMaskedTextBox>
        	txt<FieldU>.Text = null;
           <IsMultilineTextBox>
	        txt<FieldU>.Text = null;
           <IsRichTextBox>
        	txt<FieldU>.Text = null;
           <IsPictureBox>
	        txt<FieldU>.Text = null;
           <IsComboBox>
        	txt<FieldU>.SelectedIndex = -1;
           <IsComboBox (Db)>
	        txt<FieldU>.SelectedIndex = -1;
        </If Loop>
        }

        public void btnSave_Click(object sender, System.EventArgs e)
        {
		    if ((String)Session["Mode"] == "Add") {
			    this.InsertRecord();
		    } else if ((String)Session["Mode"] == "Edit") {
			    this.UpdateRecord();
		    }
        }

        private void SetData(<OwnerU>_<TableU>Class cls<OwnerU>_<TableU>)
        {
                <If Loop>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Checked ? true : false;                        
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.SelectedValue)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Checked ? true : false;  
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
			    if (string.IsNullOrEmpty(txt<FieldU>.SelectedValue)) {
			    	cls<OwnerU>_<TableU>.<FieldU> = null;
			    } else {
			    	cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Checked ? true : false);
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNotNull>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNotNull>
			    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue);
--------------------------------------------------------------------------------------------------------<Comment>
                </If Loop>
        }

        private void InsertRecord()
        {
		    <OwnerU>_<TableU>Class cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>Class();
		    if (VerifyData() == true) {
                            SetData(cls<OwnerU>_<TableU>);
			    bool bSucess = false;
			    bSucess = <OwnerU>_<TableU>DataClass.Add(cls<OwnerU>_<TableU>);
			    if (bSucess == true) {
				    pnlForm.Visible = false;
				    pnlSave.Visible = false;
				    pnlGrid.Visible = true;
				    lblMode.InnerText = "";
				    Session.Remove("dv<OwnerU>_<TableU>");
				    LoadGrid<OwnerU>_<TableU>();
			    } else {
				    ec.ShowMessage(" Insert failed. ", " <Head> ");
			    }
		    }
        }

        private void UpdateRecord()
        {
		    <OwnerU>_<TableU>Class ocls<OwnerU>_<TableU> = new <OwnerU>_<TableU>Class();
		    <OwnerU>_<TableU>Class cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>Class();

            <If Loop>
            <IsPKey>
		    ocls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
            </If Loop>
            <If Loop>
            <IsNotPKey>
            <And>
            <IsIdentity>
		    ocls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
		    ocls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
            <ExitLoop>
            </If Loop>
		    ocls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(ocls<OwnerU>_<TableU>);

		    if (VerifyData() == true) {
                            SetData(cls<OwnerU>_<TableU>);
			    bool bSucess = false;
			    bSucess = <OwnerU>_<TableU>DataClass.Update(ocls<OwnerU>_<TableU>, cls<OwnerU>_<TableU>);
			    if (bSucess == true) {
				    pnlForm.Visible = false;
				    pnlSave.Visible = false;
				    pnlGrid.Visible = true;
				    lblMode.InnerText = "";
				    Session.Remove("dv<OwnerU>_<TableU>");
				    LoadGrid<OwnerU>_<TableU>();
			    } else {
				    ec.ShowMessage(" Update failed. ", " <Head> ");
			    }
		    }
        }

        private void DeleteRecord()
        {
		    <OwnerU>_<TableU>Class cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>Class();
        <If Loop>
           <IsPKey>
		    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
		    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
		    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(Session["<FieldU>"]);
           <ExitLoop>
        </If Loop>
                    SetData(cls<OwnerU>_<TableU>);
		    bool bSucess = false;
		    bSucess = <DOwnerU>_<DTableU>DataClass.Delete(<Convert>(Session["<FieldU>"]));
		    bSucess = <OwnerU>_<TableU>DataClass.Delete(cls<OwnerU>_<TableU>);
		    if (bSucess == true) {
			    pnlForm.Visible = false;
			    pnlSave.Visible = false;
			    pnlGrid.Visible = true;
			    pnlDelete.Visible = false;
			    lblMode.InnerText = "";
			    Session.Remove("dv<OwnerU>_<TableU>");
			    LoadGrid<OwnerU>_<TableU>();
		    } else {
			    ec.ShowMessage(" Delete failed. ", " <Head> ");
		    }
        }

        private Boolean VerifyData()
        {
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsCheckBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsNumericUpDown>
		    if (txt<FieldU>.Text == "") {
		    	ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
	                txt<FieldU>.Focus();
                	return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsDateTimePicker>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsTextBox>
		    if (txt<FieldU>.Text == "") {
		    	ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
	                txt<FieldU>.Focus();
                	return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMaskedTextBox>
		    if (txt<FieldU>.Text == "") {
		    	ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
	                txt<FieldU>.Focus();
                	return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMultilineTextBox>
		    if (txt<FieldU>.Text == "") {
		    	ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
	                txt<FieldU>.Focus();
                	return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsRichTextBox>
		    if (txt<FieldU>.Text == "") {
		    	ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
	                txt<FieldU>.Focus();
                	return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsPictureBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox>
		    if (txt<FieldU>.Text == "") {
		    	ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
	                txt<FieldU>.Focus();
                	return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox (Db)>
		    if (txt<FieldU>.Text == "") {
		    	ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
	                txt<FieldU>.Focus();
                	return false;}
            </If Loop>
---------------------------------------<Comment>
            <If Loop>
            <IsNotIdentityCount>
            if (
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
            txt<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
            txt<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
            txt<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
            txt<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
            txt<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
            txt<FieldU>.SelectedIndex != -1 
	            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
            <And>
            <IsCurRow<>[0]>
            && txt<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
            <And>
            <IsCurRow<>[0]>
            && txt<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
            <And>
            <IsCurRow<>[0]>
            && txt<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
            <And>
            <IsCurRow<>[0]>
            && txt<FieldU>.Text != ""  
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
            <And>
            <IsCurRow<>[0]>
            && txt<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
            <And>
            <IsCurRow<>[0]>
            && txt<FieldU>.SelectedIndex != -1 
            <IsNotIdentity>
            <And>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
            txt<FieldU>.Text != "" 
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
            txt<FieldU>.Text != "" 
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
            txt<FieldU>.Text != "" 
           <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
            txt<FieldU>.Text != "" 
           <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
            txt<FieldU>.Text != "" 
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
            txt<FieldU>.SelectedIndex != -1 
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            )  {
            <OwnerU>_<TableU>Class cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>Class();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue);
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue);
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            cls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(cls<OwnerU>_<TableU>);
		    if (cls<OwnerU>_<TableU> != null && (String)Session["Mode"] == "Add") {
                    	ec.ShowMessage(" Record already exists. ", " <Head> ");
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
                 	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
                 	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
                 	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
                   	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
                   	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
                   	txt<FieldU>.Focus();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
                   	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
                  	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
                   	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
                  	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
                  	txt<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
                   	txt<FieldU>.Focus();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
                	return false; }
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            }
            <ExitLoop>
            </If Loop>
---------------------------------------<Comment>
		    return true;
        }

        public void butRecords_Click(object sender, System.EventArgs e)
        {
		    grd<TableU>.CurrentPageIndex = 0;
		    grd<TableU>.PageSize = Convert.ToInt32(cmbRecords.Text);
		    LoadGrid<OwnerU>_<TableU>();
        }

        public void btnAddNew_Click(object sender, System.EventArgs e)
        {
		    if (pnlForm.Visible) {
        <If Loop>
           <IsCheckBox>
			    txt<FieldU>.Checked = false;
           <IsNumericUpDown>
			    txt<FieldU>.Text = "";
           <IsDateTimePicker>
			    txt<FieldU>.Text = "";
           <IsTextBox>
			    txt<FieldU>.Text = "";
           <IsMaskedTextBox>
			    txt<FieldU>.Text = "";
           <IsMultilineTextBox>
			    txt<FieldU>.Text = "";
           <IsRichTextBox>
			    txt<FieldU>.Text = "";
           <IsPictureBox>
			    txt<FieldU>.Text = "";
           <IsComboBox>
			    txt<FieldU>.SelectedIndex = -1;
           <IsComboBox (Db)>
			    txt<FieldU>.SelectedIndex = -1;
        </If Loop>
		    } else {
			    pnlForm.Visible = true;
			    pnlGrid.Visible = false;
			    pnlSave.Visible = true;
			    lblMode.InnerText = "Add new";
		    }
		    btnSave.CommandArgument = "Add";
		    Add();
        }

        public void grd<TableU>_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        { 
		    if (e.Item.ItemType == ListItemType.Pager | e.Item.ItemType == ListItemType.Header)
			    return;

		    Button btn = (Button)e.CommandSource;
		    if (btn.Text == "Edit" | btn.Text == "Delete") {
    	<If Loop>
        	<IsPKey>
			    Session.Remove("<FieldU>");
			    Session["<FieldU>"] = e.Item.Cells[<ColNo> + <ColNo>].Text;
    	</If Loop>
    	<If Loop>
        	<IsNotPKey>
        	<And>
        	<IsIdentity>
			    Session.Remove("<FieldU>");
			    Session["<FieldU>"] = e.Item.Cells[<ColNo> + <ColNo>].Text;
        	<ExitLoop>
    	</If Loop>
    	<If Loop>
        	<IsNotIdentityCount>
        	<And>
        	<IsNotPKeyCount>
			    Session.Remove("<FieldU>");
			    Session["<FieldU>"] = e.Item.Cells[<ColNo> + <ColNo>].Text;
        	<ExitLoop>
    	</If Loop>
			    if (btn.Text == "Edit") {
				    Edit();
			    } else if (btn.Text == "Delete") {
				    Delete();
			    }
			    pnlForm.Visible = true;
			    pnlGrid.Visible = false;
			    if (btn.Text == "Edit") {
				    lblMode.InnerText = "Edit record";
				    pnlSave.Visible = true;
			    }
			    if (btn.Text == "Delete") {
				    lblMode.InnerText = "Delete record";
				    pnlDelete.Visible = true;
			    }
		    }
		    btnSave.CommandArgument = "";
        }

        public void grd<TableU>_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
        {
		    htmlHiddenSortExpression.Value = e.SortExpression + " " + GetSortDirection(e.SortExpression);
		    LoadGrid<OwnerU>_<TableU>();
        }

        public void grd<TableU>_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
		    grd<TableU>.CurrentPageIndex = e.NewPageIndex;
		    LoadGrid<OwnerU>_<TableU>();
        }

        public void butYes_Click(object sender, System.EventArgs e)
        {
		    this.DeleteRecord();
        }

        public void butNo_Click(object sender, System.EventArgs e)
        {
		    pnlDelete.Visible = false;
		    pnlGrid.Visible = true;
		    pnlForm.Visible = false;
		    lblMode.InnerText = "";
        }

        public void butCancel_Click(object sender, System.EventArgs e)
        {
		    pnlForm.Visible = false;
		    pnlSave.Visible = false;
		    pnlGrid.Visible = true;
		    lblMode.InnerText = "";
        }

        public void butOK_Click(object sender, System.EventArgs e)
        {
		    pnlMessage.Visible = false;
		    pnlGrid.Visible = true;
        }

        private void showMessage()
        {
		    lblMode.InnerText = "";
		    pnlForm.Visible = false;
		    pnlSave.Visible = false;
		    pnlDelete.Visible = false;
		    pnlGrid.Visible = false;
		    pnlMessage.Visible = true;
        }

        public void butShowAll_Click(object sender, System.EventArgs e)
        {
		    txtSearch.Text = null;
		    Session.Remove("dv<OwnerU>_<TableU>");
		    LoadGrid<OwnerU>_<TableU>();
        }

        public void butSearch_Click(object sender, System.EventArgs e)
        {
		    try {
                        Session.Remove("dv<OwnerU>_<TableU>");
			if ((Session["dv<OwnerU>_<TableU>"] != null)) {
				dv<OwnerU>_<TableU> = (DataView)Session["dv<OwnerU>_<TableU>"];
				// DataView was not found in the session.
		    	} else {
				dv<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Search(cmbFields.Text, cmbCondition.Text, txtSearch.Text).DefaultView;
			    	Session["dv<OwnerU>_<TableU>"] = dv<OwnerU>_<TableU>;
		    	}
                if (dv<OwnerU>_<TableU>.Count > 0)
                {
                    dv<OwnerU>_<TableU>.Sort = htmlHiddenSortExpression.Value;
                    grd<TableU>.DataSource = dv<OwnerU>_<TableU>;
                    grd<TableU>.DataBind();
                }
                else
                {
                    grd<TableU>.DataSource = null;
                    grd<TableU>.DataBind();
                }
		    }
		    catch (Exception ex)
		    {
		    	ec.ShowMessage(ex.Message, " <Head> ");
		    }
        }

        public void btnExport_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (ddlFile.SelectedValue == ".pdf")
                {
                    DataTable dt = new DataTable();
                    if (!string.IsNullOrEmpty(txtSearch.Text))
                    { dt = <OwnerU>_<TableU>DataClass.Search(cmbFields.Text, cmbCondition.Text, txtSearch.Text); }
                    else { dt = <OwnerU>_<TableU>DataClass.SelectAll(); }

                    PDFform pdfForm = new PDFform(dt, "<Head>", "Many");
                    Document document = pdfForm.CreateDocument();
                    PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
                    renderer.Document = document;
                    renderer.RenderDocument();

                    MemoryStream stream = new MemoryStream();
                    renderer.PdfDocument.Save(stream, false);

                    Response.Clear();
                    Response.ContentType = "application/" + ddlFile.SelectedItem.Text + ddlFile.SelectedValue;
                    Response.AddHeader("content-disposition", "attachment;filename=" + "Report" + ddlFile.SelectedValue);
                    Response.BinaryWrite(stream.ToArray());
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    Response.Clear();
                    Response.Charset = "";
                    Response.ContentEncoding = System.Text.Encoding.UTF8;
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.ContentType = "application/" + ddlFile.SelectedItem.Text + ddlFile.SelectedValue;
                    Response.AddHeader("content-disposition", "attachment;filename=" + "Report" + ddlFile.SelectedValue);

                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    HtmlTextWriter htw = new HtmlTextWriter(sw);
                    GridView GVExport = new GridView();
                    GVExport.DataSource = Session["dv<OwnerU>_<TableU>"];
                    GVExport.DataBind();
                    GVExport.RenderControl(htw);

                    Response.Write(sw);
                    sw = null;
                    htw = null;
                    Response.Flush();
                    Response.End();
                }
            }
            catch
            {
            }
        }

        private string GetSortDirection(string column)
        {
            dynamic sortDirection = "ASC";
            dynamic sortExpression = ViewState["SortExpression"] as string;
            if (sortExpression != null)
            {
                if (sortExpression == column)
                {
                    dynamic lastDirection = ViewState["SortDirection"] as string;
                    if (lastDirection != null && lastDirection == "ASC")
                    {
                        sortDirection = "DESC";
                    }
                }
            }
            ViewState["SortDirection"] = sortDirection;
            ViewState["SortExpression"] = column;
            return sortDirection;
        }

    }
}